package com.assessment.servermanager.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.assessment.servermanager.commen.utils.StringUtils;
import com.assessment.servermanager.entity.TbUser;
import com.assessment.servermanager.mapper.TbUserMapper;
import com.assessment.servermanager.service.ITbUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author jiajia
 * @date 2023-08-28
 */
@Service
public class TbUserServiceImpl implements ITbUserService {
    @Autowired
    private TbUserMapper tbUserMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public TbUser selectTbUserById(Long id) {
        return tbUserMapper.selectById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param tbUser 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TbUser> selectTbUserList(TbUser tbUser) {
        LambdaQueryWrapper<TbUser> queryWrapper = new LambdaQueryWrapper<TbUser>()
                .eq(tbUser.getId() != null,TbUser::getId,tbUser.getId())
                .eq(StringUtils.isNotEmpty(tbUser.getPhone()),TbUser::getPhone,tbUser.getPhone())
                .eq(StringUtils.isNotEmpty(tbUser.getPassword()),TbUser::getPassword,tbUser.getPassword())
                .eq(StringUtils.isNotEmpty(tbUser.getUserid()),TbUser::getUserid,tbUser.getUserid())
                .eq(StringUtils.isNotEmpty(tbUser.getEmail()),TbUser::getEmail,tbUser.getEmail());
        return tbUserMapper.selectList(queryWrapper);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tbUser 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTbUser(TbUser tbUser) {
        return tbUserMapper.insert(tbUser);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tbUser 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTbUser(TbUser tbUser) {
        return tbUserMapper.updateById(tbUser);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTbUserByIds(Long[] ids) {
        return tbUserMapper.deleteBatchIds(Arrays.stream(ids).collect(Collectors.toList()));
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTbUserById(Long id) {
        return tbUserMapper.deleteById(id);
    }

}
